/*
//   Copyright 2008 Dear Soft(http://dear-soft.com)
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
 */


package com.dear.soft.components.demo;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.dear.soft.components.path.BreadCrumb;
import com.dear.soft.components.path.PathChangeListener;
import com.dear.soft.components.path.PathPanel;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

public class Path implements DemoPanel {

	@Override
	public JComponent getGui() {
		PathPanel pathPanel = createPathPanel();
		BreadCrumb breadcrumb = createBreadcrumb();
		JPanel panel = new JPanel(new FormLayout("p:grow",
				"2dlu,p,2dlu,p,5dlu,p,2dlu,p,2dlu:grow"));
		CellConstraints cc = new CellConstraints();
		panel.add(new JLabel("Simple Breadcrumb Path: "), cc.xy(1, 2, "l,f"));
		panel.add(breadcrumb, cc.xy(1, 4, "f,f"));
		panel.add(new JLabel("Advanced Path Panel: "), cc.xy(1, 6, "l,f"));
		panel.add(pathPanel, cc.xy(1, 8, "f,f"));
		return panel;

	}

	private BreadCrumb createBreadcrumb() {
		BreadCrumb breadcrumb = new BreadCrumb();
		breadcrumb.setRoot("C:");
		breadcrumb.setPath("/Documents and Settings/Dear-Soft/jInlay/Project");
		return breadcrumb;
	}

	@Override
	public String getLabel() {
		// TODO Auto-generated method stub
		return "Breadcrumb";
	}

	private static PathPanel createPathPanel() {
		final PathPanel panel = new PathPanel("C:",
				"dear-soft.com#breadcrumbdemo");
		panel.navigateTo("/Documents and Settings/Dear-Soft/jInlay/Project");

		panel.addPathChangeListener(new PathChangeListener() {
			@Override
			public void pathChanged(String target) {
				JOptionPane.showMessageDialog(panel, "\"" + target
						+ "\" selected!");
			}

		});
		return panel;
	}

}
